﻿using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Sys;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Sys;

namespace VisionCloud.Api.Controllers.Sys
{
    /// <summary>
    /// 数据同步
    /// </summary>
    [SystemModule("数据同步")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/sys/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "数据同步")]
    public class DataSynchronizationController : ApiBaseController
    {
        public DataSynchronizationService DataSynchronizationService { get; set; }

        /// <summary>
        /// 获取项目基础数据
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        [SwaggerOperation(Tags = new[] { "项目同步" })]
        [SwaggerResponse(0, "Result", typeof(MsProjectBaseData))]
        public async Task<ApiResult> GetProjectBaseDate(GetProjectBaseParaDto param)
        {
            return await TryCatchAsync(DataSynchronizationService.GetProjectBaseDate(param.UserGuid, param.SoftwareVersion, param.ProjectIdAndVersion));
        }

        /// <summary>
        /// 获取项目的户型图
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [SwaggerOperation(Tags = new[] { "项目同步" })]
        [SwaggerResponse(0, "Result", typeof(MsHouseMapDetails))]
        public async Task<ApiResult> GetProjectHouseMaps([FromBody] ProjectIdArrayDto model)
        {
            return await DataSynchronizationService.GetProjectHouseMaps(model.ProjectIds);
        }

        /// <summary>
        /// 新增上传文件
        /// </summary>
        /// <param name="fileUploadQueue"></param>
        /// <returns></returns>
        [HttpPost]
        [SwaggerOperation(Tags = new[] { "文件上传" })]
        [SwaggerResponse(0, "Result", typeof(ResultAndMessage))]
        public async Task<ApiResult> AddInFileUploadQueue(FileUploadQueueDto fileUploadQueue)
        {
            return await TryCatchAsync(DataSynchronizationService.AddInFileUploadQueue(fileUploadQueue.DogNumber, fileUploadQueue.UploadType));
        }

        /// <summary>
        ///移除上传文件
        /// </summary>
        /// <param name="fileUploadQueue"></param>
        /// <returns></returns>
        [HttpPost]
        [SwaggerOperation(Tags = new[] { "文件上传" })]
        [SwaggerResponse(0, "Result", typeof(ResultAndMessage))]
        public async Task<ApiResult> OutFileUploadQueue(FileUploadQueueDto fileUploadQueue)
        {
            return await TryCatchAsync(DataSynchronizationService.OutFileUploadQueue(fileUploadQueue.DogNumber));
        }
    }
}